package com.yc.txx.mapper;

import com.yc.txx.entity.Car;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 车辆表 Mapper 接口
 * </p>
 *
 * @author 廖老师
 * @since 2023-04-30
 */
public interface CarMapper extends BaseMapper<Car> {

    List<Car> selectPage(@Param("brand")String brand,@Param("keyword")String keyword);

    @Select("select distinct brand from car")
    List<Map> selectBrands();


    //Results =>ResultMap
    @Results(
            id = "rm1",
            value = {
                    @Result(column = "id",property = "id",id = true),
                    @Result(column = "id",property = "images",
                    many = @Many(
                            select = "com.yc.txx.mapper.ImageMapper.selectByCid",
                            fetchType = FetchType.EAGER
                    )),
                    @Result(column = "id",property = "leases",
                    many = @Many(
                            select = "com.yc.txx.mapper.LeaseMapper.selectUnfinishByCid",
                            fetchType = FetchType.EAGER
                    ))
            }
    )
    @Select("select * from car where id = #{id}")
    Car selectById(String id);

    @Select("select * from car where id = #{id}")
    Car selectById1(String id);

    @Update("update car set state = #{state} where id = #{id}")
    void updateState(@Param("state") String state,@Param("id") String id);


 }
